
package com.kugou.game.sdk.protocol;

import com.kugou.framework.base.LogUtil;
import com.kugou.framework.http.KGHttpClient;
import com.kugou.framework.http.ResponsePackage;
import com.kugou.game.sdk.entity.ResponseMessage;
import com.kugou.game.sdk.utils.ProtocolCmd;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * 描述:找回支付密码发送验证码
 *
 * @author jerryliu
 * @since 2015年8月25日 上午10:49:10
 */
public class PayPsdCodeTask {

    public PayPsdCodeResponse request(String username, String mobile) {
        ArrayList<HashMap<String, Object>> requestParams = new ArrayList<HashMap<String, Object>>();

        HttpBaseRequestPackage req = new HttpBaseRequestPackage();
        req.setUserName(username);
        PayPsdCodeResponse respObj = new PayPsdCodeResponse();
        ResponsePackage resp = new PayPsdCodeResponsePackage();
        HashMap<String, Object> params = new HashMap<String, Object>();

        params.put("cmd", ProtocolCmd.CMD_SEND_RESET_CODE);
        params.put("username", username);
        params.put("mobile", mobile);
        requestParams.add(params);

        req.setRequestParams(requestParams);
        try {
            KGHttpClient.request(req, resp);
            resp.getResponseData(respObj);
            return respObj;
        } catch (Exception e) {
        }
        return null;
    }

    static class PayPsdCodeResponsePackage extends HttpBaseResponsePackage<PayPsdCodeResponse> {

        @Override
        protected void handleResponse(PayPsdCodeResponse response, String jsonStr) {
            try {
                LogUtil.d("response", "PayPsdCodeTask = " + jsonStr);

                JSONArray responseArray = new JSONArray(jsonStr);
                int size = responseArray.length();
                for (int i = 0; i < size; i++) {
                    JSONObject jsonResp = responseArray.getJSONObject(i);

                    String code = jsonResp.getString("code");
                    String message = jsonResp.getString("message");
                    String prompt = jsonResp.optString("prompt");
                    response.setCode(code);
                    response.setMessage(message);
                    response.setPrompt(prompt);
                }

            } catch (Exception e) {
            }
        }
    }

    public static class PayPsdCodeResponse extends ResponseMessage {
        private static final long serialVersionUID = -4820735216365527465L;
    }
}
